package com.edu.base.ums.bannerConfig.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.edu.base.ums.bannerConfig.domain.TbBannerConfig;
import com.edu.base.ums.bannerConfig.mapper.TbBannerConfigRyMapper;
import com.edu.base.ums.bannerConfig.service.ITbBannerConfigRyService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.UUIDUtils;

/**
 * banner配置Service业务层处理
 * 
 * @author lzs
 * @date 2021-02-23
 */
@Service
public class TbBannerConfigRyServiceImpl implements ITbBannerConfigRyService 
{
    @Autowired
    private TbBannerConfigRyMapper tbBannerConfigRyMapper;

    /**
     * 查询banner配置
     * 
     * @param id banner配置ID
     * @return banner配置
     */
    @Override
    public TbBannerConfig selectTbBannerConfigRyById(String id)
    {
        return tbBannerConfigRyMapper.selectTbBannerConfigRyById(id);
    }

    /**
     * 查询banner配置列表
     * 
     * @param tbBannerConfigRy banner配置
     * @return banner配置
     */
    @Override
    public List<TbBannerConfig> selectTbBannerConfigRyList(TbBannerConfig tbBannerConfigRy)
    {
        return tbBannerConfigRyMapper.selectTbBannerConfigRyList(tbBannerConfigRy);
    }

    /**
     * 新增banner配置
     * 
     * @param tbBannerConfigRy banner配置
     * @return 结果
     */
    @Override
    public int insertTbBannerConfigRy(TbBannerConfig tbBannerConfigRy)
    {
    	tbBannerConfigRy.setId(UUIDUtils.getUUID());
    	tbBannerConfigRy.setCreateBy(String.valueOf(SecurityUtils.getLoginUser().getUser().getUserId()));
    	tbBannerConfigRy.setCreateDate(new Date());
        return tbBannerConfigRyMapper.insertTbBannerConfigRy(tbBannerConfigRy);
    }

    /**
     * 修改banner配置
     * 
     * @param tbBannerConfigRy banner配置
     * @return 结果
     */
    @Override
    public int updateTbBannerConfigRy(TbBannerConfig tbBannerConfigRy)
    {
    	tbBannerConfigRy.setUpdateBy(String.valueOf(SecurityUtils.getLoginUser().getUser().getUserId()));
    	tbBannerConfigRy.setUpdateDate(new Date());
        return tbBannerConfigRyMapper.updateTbBannerConfigRy(tbBannerConfigRy);
    }

    /**
     * 批量删除banner配置
     * 
     * @param ids 需要删除的banner配置ID
     * @return 结果
     */
    @Override
    public int deleteTbBannerConfigRyByIds(String[] ids)
    {
        return tbBannerConfigRyMapper.deleteTbBannerConfigRyByIds(ids);
    }

    /**
     * 删除banner配置信息
     * 
     * @param id banner配置ID
     * @return 结果
     */
    @Override
    public int deleteTbBannerConfigRyById(String id)
    {
        return tbBannerConfigRyMapper.deleteTbBannerConfigRyById(id);
    }

	@Override
	public boolean handleUpdateStatus(String[] ids, String publishStatus) {
		// TODO 若上线，则开始时间需要大于今日
//		if ("1".equals(publishStatus)) {
//			List<TbBannerConfig> list = tbBannerConfigRyMapper.queryTbBannerByIds(ids);
//			if (CollectionUtils.isNotEmpty(list)) {
//				return false;
//			}
//		}
		tbBannerConfigRyMapper.handleUpdateStatus(ids, publishStatus); 
		return true;

	}
}
